﻿using FineUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Core;
using ZHDJ.Data.DataCaching;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.JoinParty.BLL;

namespace JoinParty.admin.FlowStep
{
    public partial class JoinPartyAppllication : PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "";
            }
        }

        //public string WebHost
        //{
        //    get { return SystemParameterCaching.Get(SystemParameterKey.WebHost); }
        //}
        #endregion
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                LoadData();
            }
        }
        private void BindData()
        {

        }

        private void LoadData(string IsSave = "")
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            PartyJoinLinkExample oModel = DB.PartyJoinLinkExamples.Find(this.CurrentStandID);
            if (oModel != null)
            {
                if (oModel.Remark!=null && oModel.Remark.Length > 10)
                    this.heContent.Text = oModel.Remark;
                else
                {

                    var html =
                    HttpRequestBusiness.WebContentByGet(WebHost + "/App/JoinParty/Template/TJoinStep19ForHtml.aspx?AppllicationID=" + AppllicationID,
                        true, WebHost + "/Login.aspx?LoginType=2");
                    this.heContent.Text = html;
                }
            }
            else
            {
                var html =
                   HttpRequestBusiness.WebContentByGet(WebHost + "/App/JoinParty/Template/TJoinStep19ForHtml.aspx?AppllicationID=" + AppllicationID,
                       true, WebHost + "/Login.aspx?LoginType=2");
                this.heContent.Text = html;
            }


            //页面只读显示
            if (this.ReadOnly.Trim() == "1")
            {
                this.btnSubmit.Visible = false;
                this.btnSaveClose.Visible = false;
                //if (IsJoinPartyAdmin && this.CurrentStepID != ProcesUtil.JoinStep9)
                //{
                //    this.btnSaveClose.Visible = true;
                //}
            }
        }



        private void SaveData(bool isSubmit = false)
        {
            string Message = "";///接收处理流程反馈的消息主要判断当前步骤是否已审核过
            bool bResult = false;
            PartyJoinLinkExample oModel = DB.PartyJoinLinkExamples.Find(this.CurrentStandID);
            oModel.HandleUserID = this.CurrentUser.ID;
            oModel.HandleUserName = this.CurrentUser.UserName;
            oModel.HandleTime = DateTime.Now;
            oModel.Remark = this.heContent.Text;
            if (isSubmit)
            {
                oModel.Status = (int)Enum_FlowStanceStatus.通过;
                bResult = ProcesUtil.ApprovalProcesStep(oModel, out Message);
            }
            else
                bResult = DB.SaveChanges() > 0;
            if (bResult)
            {
                if (isSubmit)
                {
                    Alert.Show("提交成功", String.Empty, ActiveWindow.GetHideReference());
                }
                else
                {
                    Alert.Show("保存成功", String.Empty, ActiveWindow.GetHideReference());

                }
            }
            else
            {
                if (Message != "")
                {
                    Alert.Show(Message, String.Empty, ActiveWindow.GetHideReference());
                }
            }
        }

        #endregion

        #region 按钮
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            this.SaveData(true);
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SaveData();
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion
    }
}